package com.mytx.sso.utils;

import com.alibaba.fastjson.JSONObject;
import com.mytx.common.config.MytxConfig;
import com.mytx.pojo.MytxConfigEntiy;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

public class RefreshConfigUtils {

    public static void refreshUserConfig(List<MytxConfigEntiy> mytxConfigList){
        for(MytxConfigEntiy mytxConfigEntity:mytxConfigList) {
            String mytxConfigName = mytxConfigEntity.getConfigName();
            String mytxConfigValue =  mytxConfigEntity.getConfigValue();
            if(StringUtils.equals("apk_version",mytxConfigName)){
                JSONObject configJSON = JSONObject.parseObject(mytxConfigValue);
                MytxConfig.version = configJSON.getIntValue("version");
                MytxConfig.updateLog = configJSON.getString("updateLog");
                MytxConfig.apkUrl = configJSON.getString("apk_url");
            }else if (StringUtils.equals("system_service_id",mytxConfigName)){
                MytxConfig.serviceUserId = mytxConfigValue;
            }else if (StringUtils.equals("transfer_admin_id",mytxConfigName)){
                String[] adminIds = mytxConfigValue.split(",");
                MytxConfig.adminIdList= Arrays.asList(adminIds);
            }else if(StringUtils.equals("manual_service_id",mytxConfigName)){
                MytxConfig.manualServiceId = mytxConfigValue;
            }
        }
    }
}
